package com.erp.myAdapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.erp.R
import com.erp.activity.WtPhotoActivity
import com.erp.bean.AnZhuangBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_anzhuang.view.*

/**
 * Created by Administrator on 2018/1/20/020.
 * 作者：刘洋
 */
class AnZhuangAdapter(var context: Context, var zhinanlist: MutableList<AnZhuangBean>) : BaseAdapter() {
    var minflater: LayoutInflater = LayoutInflater.from(context)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v :View
        var h : Header
        if(convertView==null){
            v=minflater.inflate(R.layout.lv_anzhuang,null)
            h= Header(v)
            v.tag=h
        }else{
            v=convertView
            h=v.tag as Header
        }
        val zhinan =zhinanlist[position]
        Myutil.settv(zhinan.shop_name,h.ShopTv)
        Myutil.settv(zhinan.customer_name,h.KeHuTv)
        Myutil.settv(zhinan.onum,h.OnumTv)
        h.IvPhoto.setOnClickListener {
            val intent = Intent(context, WtPhotoActivity::class.java)
            intent.putExtra("oid", zhinanlist[position].id)
            intent.putExtra("code", 2)
            context.startActivity(intent)
        }
        return v
    }

    override fun getItem(position: Int): Any = zhinanlist[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int = zhinanlist.size
    class Header(var v : View){
        val OnumTv=v.OnumTv
        val KeHuTv=v.KeHuTv
        val ShopTv=v.ShopTv
        val IvPhoto = v.IvPhoto
    }
}